package atomic.counter;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 使用AtomicLong
 *
 * @author <a href='https://gitee.com/hzf2281'>codefish</a>
 * @version 1.0.0
 * @since 2022/08/21 下午 07:12
 */
public class AtomicLongCounter implements Counter {
    //Long的原子类,通过CAS来保证自增的原子性
    final AtomicLong atomicLong = new AtomicLong(0);

    @Override
    public void increment() {
        atomicLong.incrementAndGet();
    }

    @Override
    public long getCount() {
        return atomicLong.get();
    }
}